package com.gdth.bank.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gdth.bank.R;
import com.gdth.database.bean.TAppBfrjThjl;
import com.gdth.utils.DateTimeUtil;

/**
 * 联系方式
 * @author arvin
 *
 */
public class CjkhThjlListViewAdapter extends BaseAdapter{
	private Context context;

	private List<TAppBfrjThjl> vList;
	
	private int layout;
	
	public CjkhThjlListViewAdapter(Context context, List<TAppBfrjThjl> vList) {  
	    this.context = context;
	    this.vList = vList;
	    
	    this.layout = R.layout.item_cjkh_thjl;
	}
	
	@Override 
	public int getCount() {  
	    return vList.size();  
	}  
	
	@Override 
	public Object getItem(int position) {  
	    return position;  
	}  
	
	@Override 
	public long getItemId(int position) {  
	    return position;  
	}
	
	@Override 
	public View getView(final int position, View convertView, ViewGroup parent) { 
		TAppBfrjThjl model = vList.get(position);
		ViewHolder holder = null;
		if (convertView == null){
			holder = new ViewHolder();
			
			convertView = LayoutInflater.from(context).inflate(layout, null);
			
		    holder.local_xm = (TextView) convertView.findViewById(R.id.cjkh_thjl_item_time);
		    holder.local_lxdh = (TextView) convertView.findViewById(R.id.cjkh_thjl_item_lxdh);
		    holder.local_cz = (ImageView) convertView.findViewById(R.id.cjkh_thjl_item_cz);
			
			convertView.setTag(holder);
	    }
		
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (holder != null){
			holder.local_xm.setText(DateTimeUtil.getCurrentTime(model.getCjsj(), "yyyy-MM-dd HH:mm:ss"));
			holder.local_lxdh.setText(model.getDhhm());
			if (mOnCallListener != null) {
				final String uuid = model.getUuid();
				holder.local_cz.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mOnCallListener.callPhone(uuid);
					}
					
				});
			}
		}
		
	    return convertView;  
	}
	
	public final class ViewHolder{
		public TextView local_xm = null;
		public TextView local_lxdh = null;
		public ImageView local_cz = null;
	}
	
	private onPhoneSpeakListener mOnCallListener;
	
	public void setOnCallListener(onPhoneSpeakListener mOnCallListener) {
		this.mOnCallListener = mOnCallListener;
	}
	
	public interface onPhoneSpeakListener {
		public void callPhone(String uuid);
	}
}
